#encoding:utf8

import sys, os, time
import datetime
import xlrd

def GetLogData(filepath):
    if os.path.exists(filepath):
        book = xlrd.open_workbook(filepath)
        sheet = book.sheet_by_index(0)
                
        num_rows= sheet.nrows        
        for row_index in range(4, num_rows):
            text= sheet.cell_value(rowx=row_index, colx=1)
            if len(text):
                isComplete= sheet.cell_value(rowx=row_index, colx=4)
                text= text.encode('gbk')+ '\t\t\t\t\t'+ isComplete.encode('gbk')
                yield text

if __name__=='__main__':
    log_dir= u'D:\\me\\perfectworld\\工作日志'    
    now= datetime.datetime.now()
    textlist= []
    for i in range(6, -1, -1):
        oldtime= now- datetime.timedelta(days=i)
        log_file_name= time.strftime(u'%Y-%m-%d', oldtime.timetuple())+u'李现民.xls'
        log_file_path= os.path.join(log_dir, log_file_name)
        if os.path.exists(log_file_path):
            textlist+= GetLogData(log_file_path)
            if i==0:
                command= u'D:\\me\DreamMail4\\DM2005.exe '+ log_file_path
#                print(type(command))
                os.system(command.encode('gbk'))
    
    # 输出到文件
    text_file_path= 'pw_log_text_friday.py.txt'
    with open(text_file_path, 'w') as fout:
        for index, item in enumerate(textlist):
            fout.write('%d: %s \n'%(index, item))
    os.system('start %s'%text_file_path)
        
